from sqlalchemy import create_engine, MetaData
from sqlalchemy.orm import sessionmaker, Session
from sqlalchemy.ext.declarative import declarative_base
from .config import config, Env

class DB:
    def __init__(self,) -> None:
        self.meta_data: MetaData = None
        self.session: Session
        self.Base = declarative_base()

    def connect(self):
        engine = create_engine(config.db_uri, echo=config.env == Env.DEV)
        # self.meta_data = MetaData(bind=engine)
        self.session = sessionmaker(bind=engine)()

    def close(self):
        if self.session is not None:
            self.session.close()

db = DB()
